import {Loading} from 'element-ui';
//loading加载
const loading = {
  option: {
    target: document.body,//Loading 需要覆盖的 DOM 节点。可传入一个 DOM 对象或字符串；若传入字符串，则会将其作为参数传入 document.querySelector以获取到对应 DOM 节点
    body: false,//同 v-loading 指令中的 body 修饰符
    fullscreen: true,//是否需要需要全屏遮罩
    lock: true,//锁定屏幕的滚动
    text: '正在执行',//显示在加载图标下方的加载文案
    customClass: ''//Loading 的自定义类名
  },
  loadingInstance: undefined,
  start: function (options) {
    const that = this;
    if (options) {
      this.option = $.extend({}, this.option, options)
    }
    this.loadingInstance = Loading.service(this.option);

    function closeLoading() {
      that.loadingInstance.close()
    }
    // 3秒关闭loading
    function endLoading() {
      setTimeout(closeLoading, 10)
    }
    function setOptionText() {
      //that.option.text = '请求超时，请重新操作';
      endLoading();
    }
    setTimeout(setOptionText, 10);
  },
  end: function () {
    this.loadingInstance.close();
  }
}
export default loading;
